﻿using System;
using System.Timers;
using System.Net.NetworkInformation;

namespace NetWatch.Tests.TestPing
{
    public class TestPing : ATest.ATest
    {
        public string Host;

        private Ping p;

        public TestPing()
        {
            p = new Ping();
        }

        public override bool Test()
        {
            bool result = true;

            try { result = p.Send(this.Host).Status == IPStatus.Success; }
            catch (Exception )
            {
                //MainForm.Current.AddItem(ex.Message);
                result = false;
            }

            return result;
        }

        public override string Info { get { return string.Format("Test Ping {0}", this.Host); } }

        protected override bool LoadTestConfig(System.Collections.Generic.Dictionary<string, object> valueList)
        {
            if (valueList.ContainsKey("Host")) this.Host = (string)valueList["Host"];

            return (!string.IsNullOrEmpty(this.Host));
        }
    }
}
